<template>
  <div class="params">
      <h4>参数设置</h4>
      <div class="container" style="height:100%;">
        <el-tabs  v-model="editableTabsValue2"  
                  type="border-card"  
                  activate-name="1"  
                  @tab-click="changeBase" 
                  height="900px">
           <el-tab-pane v-for="( item,index ) in editableTabs2" :key="item.id" :label="item.baseName" :name="item.id" style="padding: 20px;">
                    <!-- {{ item.id }} -->
                    <!-- 早市晚市 设置 -->
                <div class="set_time">
                    <div class="morning">
                        <h4>日供时间设置
                            <el-switch  v-model="morningSwitch" @click.native="changeMorning()">
                            </el-switch>
                        </h4>
                        <div class="demo-input-suffix" style="margin-bottom:20px;display:block;">
                            <span style="width:150px;">供应端可发布时间：</span>
                            <!-- <el-time-picker
                                    is-range
                                    v-model="time1"
                                    range-separator="至"
                                    start-placeholder="开始时间"
                                    end-placeholder="结束时间"
                                    value-format="HH:mm:ss"
                                    style="width:308px;"
                                    placeholder="选择时间范围"
                                   >
                           </el-time-picker> -->
                           <el-time-picker
                                    v-model="value1"
                                    placeholder="开始时间" 
                                    value-format="HH:mm:ss"
                                    style="width:140px;">
                            </el-time-picker>
                              —
                            <el-time-picker
                                    v-model="value2"
                                    value-format="HH:mm:ss"
                                    placeholder="结束时间" 
                                    style="width:140px;">
                            </el-time-picker>
                        </div>
                        <div class="demo-input-suffix" style="margin-bottom:20px;display:block;">
                            <span style="width:100px;">商户可购买时间：</span> 
                             <!-- <el-time-picker
                                    is-range
                                    type="datetimerange"
                                    v-model="time2"
                                    range-separator="至"
                                    start-placeholder="开始时间"
                                    end-placeholder="结束时间"
                                    value-format="HH:mm:ss"
                                    style="width:308px;"
                                    placeholder="选择时间范围">
                            </el-time-picker> -->
                            <el-time-picker
                                    v-model="value3"
                                    placeholder="开始时间" 
                                    value-format="HH:mm:ss"
                                    style="width:140px;">
                            </el-time-picker>
                              —
                            <el-time-picker
                                    v-model="value4"
                                    value-format="HH:mm:ss"
                                    placeholder="结束时间" 
                                    style="width:140px;">
                            </el-time-picker>
                        </div>
                    </div>
                    <div class="evening">
                        <h4>周供时间设置
                             <el-switch  v-model="eveningSwitch" @click.native="changeEvening()">
                             </el-switch>
                        </h4>
                        <div class="demo-input-suffix" style="margin-bottom:20px;display:block;">
                            <span style="width:150px;">供应端可发布时间：</span>
                             <!-- <el-time-picker
                                    is-range
                                    type="datetimerange"
                                    v-model="time3"
                                    range-separator="至"
                                    start-placeholder="开始时间"
                                    end-placeholder="结束时间"
                                    value-format="HH:mm:ss"
                                    style="width:308px;"
                                    placeholder="选择时间范围"
                                   >
                           </el-time-picker> -->
                           <el-time-picker
                                    v-model="value5"
                                    placeholder="开始时间" 
                                    value-format="HH:mm:ss"
                                    style="width:140px;">
                            </el-time-picker>
                              —
                            <el-time-picker
                                    v-model="value6"
                                    value-format="HH:mm:ss"
                                    placeholder="结束时间" 
                                    style="width:140px;">
                            </el-time-picker>
                        </div>
                        <div class="demo-input-suffix" style="margin-bottom:20px;display:block;">
                            <span style="width:100px;">商户可购买时间：</span> 
                            <el-time-picker
                                    v-model="value7"
                                    placeholder="开始时间" 
                                    value-format="HH:mm:ss"
                                    style="width:140px;">
                            </el-time-picker>
                              —
                            <el-time-picker
                                    v-model="value8"
                                    value-format="HH:mm:ss"
                                    placeholder="结束时间" 
                                    style="width:140px;">
                            </el-time-picker>
                        </div>
                    </div>
                </div>
                <div><el-button type="primary" @click="saveTime()" style="margin-left:24px;">保存</el-button></div>
                <hr style="margin: 10px 0;background-color:#ccc;height:1px;border:none;'">
                <div>
                   龙虾规格包装设置 ：<el-button type="primary" @click="addSize()">新增</el-button>
                </div>
               <!-- 龙虾规格 表格 -->
                <el-table  :data="tableSize" style="width: 600px;margin:20px;height:250px;" border>
                    <el-table-column prop="sizeName"  label="龙虾规格"  width="128" align="center"></el-table-column>
                    <el-table-column  prop="weight" label="起卖斤数" width="130" align="center"></el-table-column>
                    <el-table-column  prop="weight" label="更换显示顺序" width="120" align="center">
                       <template slot-scope="scope">
                            <!-- <i class="el-icon-arrow-down"   v-if="scope.row.isFlagTop" style="font-size:24px;float:left;margin-left:10px;" @click="download( scope.row.id)"></i>
                            <i class="el-icon-arrow-up"     v-if="scope.row.isFlagDown"  style="font-size:24px;margin-right:20px;float:right;" @click="upload2( scope.row.id)"></i> -->
                            <img src="../common/img/down.png" v-if="scope.row.isFlagTop" style="width:30px;height:30px;float:left;margin-left:10px;" @click="download( scope.row.id)" />
                            <img src="../common/img/down_opacity.png" v-if="!scope.row.isFlagTop" style="width:30px;height:30px;float:left;margin-left:10px;"/>
                            <img src="../common/img/up.png"  v-if="scope.row.isFlagDown"    style="width:30px;height:30px;margin-right:20px;float:right;" @click="upload2( scope.row.id)"/>
                            <img src="../common/img/up_opacity.png"  v-if="!scope.row.isFlagDown"    style="width:30px;height:30px;margin-right:20px;float:right;"/>
                        </template> 
                    </el-table-column>
                    <el-table-column label="操作"  align="center" width='220px'>
                        <template slot-scope="scope">
                            <el-button size="mini" type="warning" @click="handleEditSize(scope.row.id,scope.row.sizeName,scope.row.weight)">编辑</el-button>
                            <el-button size="mini" type="danger" @click="handleDelSize( scope.row.id)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                请您选择产品规格添加售价区间以及建议售价：
                <el-button type="primary" @click="addPrice()">新增</el-button>
                 <br />
                <el-select v-model="value" placeholder="请选择规格搜索相关数据" @change="search()">
                    <el-option  v-for="item in options" :key="item.value" :label="item.goodSize" :value="item.id">
                    </el-option>
                </el-select>
                <el-button type="primary" @click="search()">搜索</el-button>
               <!--根据规格 去查找对应的数据表格  -->
                <el-table  :data="tableData" style="width: 900px;margin-top:20px;" border>
                    <el-table-column prop="sizeName" label="XX斤起卖"  width="120"></el-table-column>
                    <el-table-column prop="date"  label="日期"  width="180"></el-table-column>
                    <el-table-column prop="priceRange" label="售价区间"  width="180"> </el-table-column>
                    <el-table-column  prop="recomPrice" label="建议售价"></el-table-column>
                    <el-table-column label="操作"  align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="warning" @click="handlePriceEdit(scope.row)">编辑</el-button>
                            <el-button size="mini" type="danger" @click="handlePriceDel( scope.row.id)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
        </el-tabs>
      </div>
      <!-- 新增龙虾规格模态框   -->
      <el-dialog  title="龙虾规格/包装设置" :visible.sync="dialogFormVisible" width="40%" top="18vh">
            <el-form :model="form" :rules="rules" ref="ruleForm1">
                <el-form-item prop="lxSize" label="龙虾规格" :label-width="formLabelWidth">
                       <el-input v-model="form.lxSize" auto-complete="on" style="width:360px;"></el-input>
                </el-form-item>
                <el-form-item prop="bzSize" label="起卖斤数" :label-width="formLabelWidth">
                       <el-input v-model="form.bzSize" auto-complete="on" style="width:360px;" placeholder="请输入起卖斤数（如：20）"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit('ruleForm1')">保存</el-button>
            </div>
     </el-dialog>
       <!--龙虾价格区间设置模态框   -->
        <el-dialog  title="龙虾价格区间设置"  :visible.sync="priceMask" width="40%" top="18vh">
            <el-form :model="formPrice" :rules="rules1" ref="ruleForm">
                 <el-form-item prop="valueId" label="规格类型" :label-width="formLabelWidth">
                      <el-select v-model="formPrice.valueId" placeholder="请选择规格搜索相关数据">
                              <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.goodSize"
                                :value="item.id">
                              </el-option>
                       </el-select>
                </el-form-item>
                <el-form-item prop="heightPrice" label="最高价" :label-width="formLabelWidth">
                       <el-input v-model="formPrice.heightPrice" auto-complete="on" style="width:360px;"></el-input>
                </el-form-item>
                <el-form-item prop="heightPrice" label="最低价" :label-width="formLabelWidth">
                       <el-input v-model="formPrice.lowPrice" auto-complete="on" style="width:360px;"></el-input>
                </el-form-item>
               <el-form-item prop="recomPrice" label="建议售价" :label-width="formLabelWidth">
                       <el-input v-model="formPrice.recomPrice" auto-complete="on" style="width:360px;"></el-input>
                </el-form-item>
                <el-form-item prop="date" label="日期" :label-width="formLabelWidth">
                      <el-date-picker v-model="formPrice.date"  value-format="yyyy-MM-dd"
                                      type="date" placeholder="选择日期"
                                     :picker-options="pickerOptions1">
                      </el-date-picker>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="priceMask = false">取 消</el-button>
                <el-button type="primary" @click="savePriceEdit('ruleForm')">保存</el-button>
            </div>
        </el-dialog>
       <!-- 删除龙虾价格规格的模态框 -->
  </div>
</template>

<script>
import { farmer_base,addSize,baseParams,getSizeParams,
          paramsSize,priceDay,updateSizeParams,delSizeParams,
          addPriceToday,updatesizeDay,delPriceDay,
          setTime,getTimeParams,
          changeSwitch,
          UpdataSort
       } from '@/request/api'
          
 export default {
      data(){
         var checkBlank = (rule, value, callback) => {
            if (/(^\s+)|(\s+$)|\s+/g.test(value)) {
                callback(new Error('请不要输入空格'));
            }else {
                callback()
            } 
        };
        return {
            value1:'',
            value2:'',
            value3:'',
            value4:'',
            value5:'',
            value6:'',
            value7:'',
            value8:'',

            timeId:'',
            morningSwitch:true,
            eveningSwitch:false,
            editableTabsValue2: '',  // tab栏绑定 基地id
            editableTabs2: [],      // tab 栏导航内容
            options: [],  // 龙虾各种规格下拉框
            formLabelWidth:'120px',
            form:{
               isEdit:false,
               id:'' , // 龙虾规格id
               lxSize:'' , // 龙虾规格
               bzSize:'',  // 包装规格
            }, // 龙虾规格 新增 from 值 
            rules: {
                 lxSize: [
                    { required: true, message: '龙虾规格不能为空', trigger: 'blur' },
                     { validator: checkBlank, trigger: 'blur' }
                 ],
                 bzSize: [
                     { required: true, message: '起卖斤数不能为空', trigger: 'blur' },
                     { validator: checkBlank, trigger: 'blur' },
                     { pattern:/^[0-9]*$/, message: '只能输入数字', trigger: 'blur'}
                 ]
            },
            rules1: {
                 lowPrice: [
                     { required: true, message: '最低价不能为空', trigger: 'blur' },
                     { validator: checkBlank, trigger: 'blur' }
                 ],
                 heightPrice: [
                     { required: true, message: '最高价不能为空', trigger: 'blur' },
                     { validator: checkBlank, trigger: 'blur' }
                 ],
                 recomPrice: [
                     { required: true, message: '建议售价不能为空', trigger: 'blur' },
                     { validator: checkBlank, trigger: 'blur' }
                 ],
                 date: [
                     { required: true, message: '日期不能为空', trigger: 'change' },
                     { validator: checkBlank, trigger: 'blur' }
                 ],
                 valueId:[
                     { required: true, message: '类型不能为空', trigger: 'blur' },
                 ]
            },
            dialogFormVisible:false,
            tableSize: [{
                date: '4-6 钱',
                name: '20'
             }, 
             {
                date: '7-8 钱',
                name: '30'
             }, 
             {
                date: '一两以上',
                name: '40'
             }
            ], // 龙虾规格 表格 
            tableData: [],
            tableSize:[], //  价格设置  
            value: '',  // 龙虾规格下拉框 绑定的数值 
            tabIndex: 2,
            base:'',
            time1:'',
            time2:'',
            time3:'',
            time4:'' , // 
            baseId:'' ,  // 当前选中的baseId 的数值 基地id值  
            priceMask:false,
            formPrice:{
                isEdit:false,
                lowPrice:'',
                heightPrice:'',
                recomPrice:'',
                date:'',
                valueId:'',
                id:''
            },
            array:[],
            arrayId:[],
            pickerOptions1: {
                    disabledDate(time) {
                        var curDate = new Date();
                        console.log(curDate);
                        return  time.getTime() < new Date(curDate.getTime() - 24*60*60*1000);
                    }
            },
             //imgUrl:require("../assets/")
        }
       
      },
      created(){
          farmer_base().then(res => {
                console.log(res);
                // 获取 tab 选项卡中基地
                this.editableTabs2 = res.data.map( ( v , index ) => {
                    // v.name =  (index + 1).toString();
                    v.id = v.id.toString();
                    return v;
                });
                this.baseId =  this.editableTabs2[0].id;  // 获取基地id 
                this.editableTabsValue2 = this.editableTabs2[0].id; // 给选项卡设置默认的显示基地
                // 查询龙虾规格
                this.getSize();
                //  查询参数规格;
                this.get_paramsSize();
                // 如果有时间参数 需要获取
                this.get_time();
         })
      },
      methods:{
          changeMorning(){
             let msg = !this.morningSwitch ? '确认关闭日供吗':'确认开通日供吗' ;
             let info = !this.morningSwitch ? '已取消关闭日供':'已取消开通日供';
             let infoMsg = !this.morningSwitch ? '关闭日供成功' : '开通日供成功';
             let infoMsg1 = !this.morningSwitch ? '关闭日供失败' : '开通日供失败'
             this.$confirm(msg, "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
             }).then(()=>{
                    changeSwitch({
                        paramId:this.timeId,
                        category:1
                    }).then(res => {
                         console.log(res)
                         if(res.code == 1) {
                             this.$message({
                                type: 'success',
                                message: infoMsg
                             });  
                             this.get_time();
                         }
                         if(res.code == 0) {
                              this.$message({
                                type: 'error',
                                message: infoMsg1
                             });  
                             this.get_time();
                         }
                          
                    })
                }).catch(()=>{
                    this.$message({
                        type: 'info',
                        message: '已取消开通日供'
                    }); 
                    this.get_time(); 
                }) 
          },
          changeEvening(){
             let msg = !this.eveningSwitch  ? '确认关闭周供吗':'确认开通周供吗' ;
             let info = !this.eveningSwitch ? '已取消关闭周供':'已取消开通周供';
             let infoMsg = !this.eveningSwitch ? '关闭周供成功' : '开通周供成功';
             let infoMsg1 = !this.eveningSwitch ? '关闭周供失败' : '开通周供失败';
             this.$confirm(msg, "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
               }).then(()=>{
                  changeSwitch({
                        paramId:this.timeId,
                        category:2
                    }).then(res => {
                         if(res.code == 1) {
                             this.$message({
                                type: 'success',
                                message: infoMsg
                             });  
                              this.get_time();
                         }
                         if(res.code == 0) {
                              this.$message({
                                type: 'error',
                                message: infoMsg1
                             });  
                             this.get_time();
                         }
                    })
                  
                }).catch(()=>{
                    this.$message({
                            type: 'info',
                            message: info
                    });  
                }) 
          },
          handleDelSize(id){
                // 删除龙虾规格
           this.$confirm("此操作将永久删除, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
            }).then(()=>{
                delSizeParams({
                    id:id
                }).then(res => {
                    console.log(res);
                    if(res.code ==1) {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.dialogFormVisible = false ;
                        this.getSize();
                        this.get_paramsSize();
                        return false;

                    }
                    if(res.code == 3) {
                        this.$message({
                            type: 'info',
                            message: '该规格已被发布，不能删除!'
                        });
                        return false;
                    }
                    
                })
                }).catch(()=>{
                    this.$message({
                            type: 'info',
                            message: '已取消删除'
                    });  
                }) 
          },
          // 获取龙虾规格表格 
          getSize(){
                getSizeParams({
                   baseId:this.editableTabsValue2
                }).then(res => {
                    this.tableSize = res.data;
                    this.tableSize = res.data.map( (v,i) => {
                          if( i == 0) {
                              v.isFlagTop = true;
                              v.isFlagDown = false;
                          }else if( i == res.data.length -1)  {
                               v.isFlagTop = false;
                               v.isFlagDown = true;
                          }else {
                              v.isFlagTop = true;
                              v.isFlagDown = true; 
                          }
                          return v;
                         
                    })
 
                })
          },
        //向下排序
          download(catId,e){
            this.arrayId=[];
            for(var i=0;i<this.tableSize.length;i++){  
                if(catId==this.tableSize[i].id){
                    var commentId=this.tableSize[i].id;
                        this.tableSize[i].id=this.tableSize[i+1].id;
                        this.tableSize[i+1].id= commentId;
                        this.array=this.tableSize;
                        break;
                }
            }
            for(var i=0;i<this.array.length;i++){
                this.arrayId.push(this.array[i].id)
                    // break;      
                            
            }
             UpdataSort({
                 ids:this.arrayId.join(',')
             }).then(res=>{
               console.log(res)
               this.getSize();
             })
          },
        // 向上排序
          upload2(catId){
             this.arrayId=[]; 
             for(var i=0;i<this.tableSize.length;i++){ 
                 if(catId==this.tableSize[i].id){
                     var commentId=this.tableSize[i].id;
                         this.tableSize[i].id=this.tableSize[i-1].id;
                         this.tableSize[i-1].id= commentId;
                         this.array=this.tableSize;
                         break;
                 }  
             }
            for(var i=0;i<this.array.length;i++){
                this.arrayId.push(this.array[i].id)
                               
            }
             UpdataSort({
                 ids:this.arrayId.join(',')
             }).then(res=>{
               console.log(res)
               this.getSize();
             })
          },
          handleEditSize(id,lxSize,bzSize){
            //  编辑基地规格参数,
                console.log(id,lxSize,bzSize);
                this.form.isEdit = true;
                this.form.id = id;
                this.form.lxSize = lxSize;
                this.form.bzSize = bzSize;
                this.dialogFormVisible = true;
          },
          // tab 选项卡切换基地 
          changeBase() { 
                this.getSize();
                //  查询参数规格;
                this.get_paramsSize(); // 获取下拉框
                // 如果有时间参数 需要获取
                console.log(this.editableTabsValue2);
                this.get_time();
          },
          // 新增龙虾开启模态框
          addSize(){
              this.dialogFormVisible = true;
              this.form.isEdit = false;
              this.form.lxSize = '';
              this.form.bzSize = '';
          },
        //   保存的时候 价格
         saveEdit(formName) { // 新增基地规格  
             this.$refs[formName].validate((valid) =>{
                if(valid) {
                   // 新增规格 
                   if(this.form.isEdit) {
                     //    编辑龙虾规格
                     updateSizeParams({
                            id:this.form.id,
                            baseId:this.editableTabsValue2,
                            size: this.form.lxSize,
                            weight:this.form.bzSize
                     }).then(res => {
                          console.log(res);
                        //   编辑成功之后刷新页面 
                         if(res.code == 1) {
                               this.$message({
                                    type: 'success',
                                    message: '基地规格编辑成功!'
                                });
                                this.getSize();
                                this.dialogFormVisible = false;
                                this.get_paramsSize(); // 获取下拉框
                         }
                     }) 
                   }else {
                    //   新增龙虾规格
                        addSize({
                            baseId:this.editableTabsValue2,
                            size: this.form.lxSize,
                            weight:this.form.bzSize
                        }).then(res => {
                            console.log(res);
                            if(res.code == 1) {
                                this.dialogFormVisible = false;
                                this.$message({
                                    type: 'success',
                                    message: '基地规格设置成功!'
                                });
                                this.form.id = '';
                                this.lxSize = '';  // 龙虾规格
                                this.bzSize = '';
                                this.getSize();
                                //  刷新 下拉框中的值 
                                 this.get_paramsSize(); // 获取下拉框
                            }
                            if(res.code == 2) {
                                this.$message({
                                    type: 'warning',
                                    message: '规格最多只能设置5个'
                                });
                                 this.dialogFormVisible = false;
                            }
                        }) 
                   }   
                }
             })
          },
          get_paramsSize(){ // 获取下拉框  
             paramsSize({
                 baseId:this.editableTabsValue2
             }).then( res  => {
                    this.options = res.data;
                    if(this.options.length != 0 ) {
                        this.value = res.data[0].id; // 让下拉框默认显示数值 
                    }else {
                        this.value = ''; 
                    }
                   //  获取表格数据 
                 this.get_priceDay();
             }) 
          },
          get_priceDay(){ // 获取龙虾每日价格
              priceDay({
                  baseId:this.editableTabsValue2,
                  sizeId:this.value
              }).then(res => {
                   console.log(res);
                   this.tableData = res.data;
                
              })
          },
          search(){
              this.get_priceDay();
          },
          addPrice(){
              this.priceMask = true;  
          },
          savePriceEdit(formName){
                //  保存龙虾价格 接口 
             this.$refs[formName].validate((valid) => {
                 if(valid) {
                   if(this.formPrice.lowPrice > this.formPrice.heightPrice ) {
                         this.$message({
                                type: 'info',
                                message: '最低价不能大于最高价'
                         });
                         this.formPrice.lowPrice = '';
                         this.formPrice.heightPrice = ''; 
                         return false;
                   }
                   if( this.formPrice.recomPrice < this.formPrice.lowPrice  ) {
                        this.$message({
                                    type: 'info',
                                    message: '建议售价不能低于最低价'
                         });
                         this.formPrice.recomPrice = '';
                         return false;
                   }
                    if( this.formPrice.recomPrice >  this.formPrice.heightPrice  ) {
                        this.$message({
                                    type: 'info',
                                    message: '建议售价不能高于最高价'
                         });
                         this.formPrice.recomPrice = '';
                         return false;
                   }
                   if(this.formPrice.isEdit) {
                   //  编辑接口 
                       updatesizeDay({
                           id:this.formPrice.id,
                           belongBase:this.editableTabsValue2,
                           sizeId:this.formPrice.valueId,
                           lowPrice:this.formPrice.lowPrice,
                           date:this.formPrice.date,
                           highPrice:this.formPrice.heightPrice,    
                           recomPrice:this.formPrice.recomPrice  
                       }).then(res => {
                            if(res.code == 1) {
                               this.$message({
                                    type: 'success',
                                    message: '编辑龙虾规格每日价格新增成功!'
                               });
                               this.priceMask = false;
                            //    刷新表格 
                                this.get_priceDay(); 
                            }
                            if(res.code == 3) {
                                 this.$message({
                                    type: 'info',
                                    message: '不能编辑今日之前的价格!'
                                 });
                                 this.priceMask = false;
                                  this.get_priceDay(); 
                            }
                       })
                   }else {
                    //  新增
                       addPriceToday({
                           belongBase:this.editableTabsValue2,
                           sizeId:this.formPrice.valueId,
                           lowPrice:this.formPrice.lowPrice,
                           date:this.formPrice.date,
                           highPrice:this.formPrice.heightPrice,    
                           recomPrice:this.formPrice.recomPrice
                       }).then(res => {
                            if(res.code == 1) {
                                this.$message({
                                    type: 'success',
                                    message: '龙虾规格每日价格新增成功!'
                                });
                                 this.formPrice.lowPrice = '';
                                 this.formPrice.heightPrice = '';
                                 this.formPrice.recomPrice = '';
                                 this.formPrice.date = '';
                                 this.priceMask = false;
                                 this.get_priceDay(); 
                            }
                            if(res.code == 0) {
                                this.$message.error('同一种规格价设置日期不能一样哦');

                            }
                       })
                   }
                 }
             })
                
          },
          handlePriceDel(id) {
            //   删除每日龙虾价格
            this.$confirm("此操作将永久删除, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
            }).then(()=>{
                delPriceDay({
                    id:id
                }).then(res => {
                    if(res.code ==1) {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                         this.get_priceDay(); 
                    }
                    if(res.code == 3) {
                          this.$message({
                            type: 'info',
                            message: '不能删除今日之前的价格'
                         });  
                    }
                })
                }).catch(()=>{
                    this.$message({
                            type: 'info',
                            message: '已取消删除'
                    });  
                }) 
          },
        //   编辑龙虾每日价格
          handlePriceEdit(obj) {
              console.log(obj);
              this.priceMask = true;
              this.formPrice.isEdit  = true;
              this.formPrice.lowPrice = obj.lowPrice;
               this.formPrice.heightPrice = obj.highPrice;
               this.formPrice.recomPrice = obj.recomPrice;
               this.formPrice.date = obj.date;
               this.formPrice.valueId = obj.sizeId;
               this.formPrice.id = obj.id;
          },
          saveTime(){
                // var t1 = this.time1[1];
                // var t2 = this.time3[0];
                // var t3 = this.time2[1];
                // var t4 = this.time4[0];
                // var t1 = this.value2;
                // var t2 = this.value5;
                // var t3 = this.value4;
                // var t4 = this.value7;
                // var c1 = Date.parse('2008-08-08 '+t1);
                // var c2 = Date.parse('2008-08-08 '+t2);
                // var c3 = Date.parse('2008-08-08 '+t3);
                // var c4 = Date.parse('2008-08-08 '+t4);
                // if (c1 > c2) {
                //    this.$message({
                //         type: 'info',
                //         message: '晚市发布开始时间不能早于早市发布结束时间'
                //    });  
                //    this.time1 = '';
                //    this.time3 = '';
                //    return false;

                // } 
                // if (c3 > c4) {
                //     this.$message({
                //             type: 'info',
                //             message: '晚市购买开始时间不能早于早市购买结束时间'
                //     }); 
                //     this.time2 = '';
                //     this.time4 = '';  
                //     return flase;
                // } 
            
            //   保存早市晚市  时间设置
             setTime({
                 baseId:this.editableTabsValue2,
                 deStartM:this.value1, // 早市发布开始时间
                 deEndM:this.value2,         //  早市发布结束时间 
                 purStartM:this.value3,       // 商户购买开始时间
                 purEndM:this.value4,        // 商户购买结束时间
                 deStartE:this.value5,         // 晚市发布开始时间
                 deEndE:this.value6,          // 晚市发布结束时间
                 purStartE:this.value7,        // 晚市购买开始时间
                 purEndE:this.value8          // 晚市购买结束时间
             }).then(res => {
                  console.log(res);
                  if(res.code == 1) {
                      this.$message({
                            type: 'success',
                            message: '设置成功'
                       });   
                       this.get_time();
                  }
             })
          },
          get_time(){
              getTimeParams({
                 id:this.editableTabsValue2   
              }).then(res => {
                   console.log(res);
                   this.timeId = res.data.id;
                   if(res.data.openM == 1) {
                       this.morningSwitch = true;
                   }
                   if(res.data.openM == 0) {
                       this.morningSwitch = false;
                   }
                   if(res.data.openE == 1) {
                       this.eveningSwitch = true;
                   }
                   if(res.data.openE == 0) {
                       this.eveningSwitch = false;
                   }
                //    this.time1 = [res.data.deStartM,res.data.deEndM];
                //    this.time2 = [res.data.purStartM,res.data.purEndM];
                //    this.time3 = [res.data.deStartE,res.data.deEndE];
                //    this.time4 = [res.data.purStartE,res.data.purEndE];
                   this.value1 = res.data.deStartM;
                   this.value2 = res.data.deEndM;
                   this.value3 = res.data.purStartM;
                   this.value4 = res.data.purEndM;
                   this.value5 = res.data.deStartE;
                   this.value6 = res.data.deEndE;
                   this.value7 = res.data.purStartE;
                   this.value8 = res.data.purEndE;
                   
              })
          }
         
      }
 }

</script>
<style  scoped>
.params > h4 {
    line-height: 22px;
    border-left: 5px solid rgb(32, 160, 255);
    font-size:16px;
    color: #666;
    padding-left:  10px;
    font-size:18px;
    margin-bottom:20px;
}
.set_time {
     display: flex;
     padding: 15px;
     /* border-bottom: 1px solid #ccc; */
     
}
.set_time > div {
    flex: 1;
}

</style>